package com.runfast.waimai.service.impl;

import com.runfast.common.service.BaseService;
import com.runfast.waimai.dao.model.Notice;
import com.runfast.waimai.dao.model.RunfastBusinessalliance;
import com.runfast.waimai.dao.model.RunfastBusinessallianceExample;
import com.runfast.waimai.service.NoticeService;
import com.runfast.waimai.service.RunfastBusinessallianceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RunfastBusinessallianceServiceImpl extends BaseService<RunfastBusinessalliance, Integer, RunfastBusinessallianceExample> implements RunfastBusinessallianceService {
    @Autowired
    private NoticeService noticeService;
     public void BusinessallianceToNotice(){
         RunfastBusinessallianceExample example=new RunfastBusinessallianceExample();
         example.createCriteria().andHavereadEqualTo(false);
         List<RunfastBusinessalliance> runfastBusinessallianceList=this.mapper.selectByExample(example);
         if(runfastBusinessallianceList.size()>0){
             for(RunfastBusinessalliance runfastBusinessalliance:runfastBusinessallianceList){
                 Notice notice=new Notice();
                 notice.setTitle("商家入驻申请："+runfastBusinessalliance.getBusinessname());
                 if(runfastBusinessalliance.getAgentid()!=null){
                     notice.setAgentid(runfastBusinessalliance.getAgentid());
                 }else{notice.setOnlyadmin(true);}
                 notice.setCreatetime(new Date());
                 notice.setHaveread(false);
                 notice.setDeleted(false);
                 String s="<p><strong>商家名称</strong>："+runfastBusinessalliance.getBusinessname()
                         +"</p><p><br></p><p><strong>联系电话</strong>："+runfastBusinessalliance.getMoblie()
                         +"</p><p><br></p><p><strong>联系人</strong>："+runfastBusinessalliance.getBusinessname()
                         +"</p><p><br></p><p><strong>联系地址</strong>："+runfastBusinessalliance.getAddress()
                         +"</p><p><br></p><p><strong>备注</strong>："+runfastBusinessalliance.getRemark()
                         +"</p><p><br></p><p><strong>加盟地</strong>："+runfastBusinessalliance.getLocal()+"</p>";
                 notice.setContent(s);
                 noticeService.insert(notice);
                 runfastBusinessalliance.setHaveread(true);
                 this.mapper.updateByPrimaryKeySelective(runfastBusinessalliance);
             }
         }
    }
}